1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module soup.Multipart;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import linker.Loader;
31 private import soup.Buffer;
32 private import soup.MessageBody;
33 private import soup.MessageHeaders;
34 private import soup.c.functions;
35 public  import soup.c.types;
36 
37 
38 /**
39  * Represents a multipart HTTP message body, parsed according to the
40  * syntax of RFC 2046. Of particular interest to HTTP are
41  * <literal>multipart/byte-ranges</literal> and
42  * <literal>multipart/form-data</literal>.
43  * 
44  * Although the headers of a #SoupMultipart body part will contain the
45  * full headers from that body part, libsoup does not interpret them
46  * according to MIME rules. For example, each body part is assumed to
47  * have "binary" Content-Transfer-Encoding, even if its headers
48  * explicitly state otherwise. In other words, don't try to use
49  * #SoupMultipart for handling real MIME multiparts.
50  *
51  * Since: 2.26
52  */
53 public class Multipart
54 {
55 	/** the main Gtk struct */
56 	protected SoupMultipart* soupMultipart;
57 	protected bool ownedRef;
58 
59 	/** Get the main Gtk struct */
60 	public SoupMultipart* getMultipartStruct(bool transferOwnership = false)
61 	{
62 		if (transferOwnership)
63 			ownedRef = false;
64 		return soupMultipart;
65 	}
66 
67 	/** the main Gtk struct as a void* */
68 	protected void* getStruct()
69 	{
70 		return cast(void*)soupMultipart;
71 	}
72 
73 	/**
74 	 * Sets our main struct and passes it to the parent class.
75 	 */
76 	public this (SoupMultipart* soupMultipart, bool ownedRef = false)
77 	{
78 		this.soupMultipart = soupMultipart;
79 		this.ownedRef = ownedRef;
80 	}
81 
82 	~this ()
83 	{
84 		if ( Linker.isLoaded(LIBRARY_SOUP[0]) && ownedRef )
85 			soup_multipart_free(soupMultipart);
86 	}
87 
88 
89 	/** */
90 	public static GType getType()
91 	{
92 		return soup_multipart_get_type();
93 	}
94 
95 	/**
96 	 * Creates a new empty #SoupMultipart with a randomly-generated
97 	 * boundary string. Note that @mime_type must be the full MIME type,
98 	 * including "multipart/".
99 	 *
100 	 * Params:
101 	 *     mimeType = the MIME type of the multipart to create.
102 	 *
103 	 * Returns: a new empty #SoupMultipart of the given @mime_type
104 	 *
105 	 * Since: 2.26
106 	 *
107 	 * Throws: ConstructionException GTK+ fails to create the object.
108 	 */
109 	public this(string mimeType)
110 	{
111 		auto __p = soup_multipart_new(Str.toStringz(mimeType));
112 
113 		if(__p is null)
114 		{
115 			throw new ConstructionException("null returned by new");
116 		}
117 
118 		this(cast(SoupMultipart*) __p);
119 	}
120 
121 	/**
122 	 * Parses @headers and @body to form a new #SoupMultipart
123 	 *
124 	 * Params:
125 	 *     headers = the headers of the HTTP message to parse
126 	 *     body_ = the body of the HTTP message to parse
127 	 *
128 	 * Returns: a new #SoupMultipart (or %NULL if the
129 	 *     message couldn't be parsed or wasn't multipart).
130 	 *
131 	 * Since: 2.26
132 	 *
133 	 * Throws: ConstructionException GTK+ fails to create the object.
134 	 */
135 	public this(MessageHeaders headers, MessageBody body_)
136 	{
137 		auto __p = soup_multipart_new_from_message((headers is null) ? null : headers.getMessageHeadersStruct(), (body_ is null) ? null : body_.getMessageBodyStruct());
138 
139 		if(__p is null)
140 		{
141 			throw new ConstructionException("null returned by new_from_message");
142 		}
143 
144 		this(cast(SoupMultipart*) __p);
145 	}
146 
147 	/**
148 	 * Adds a new MIME part containing @body to @multipart, using
149 	 * "Content-Disposition: form-data", as per the HTML forms
150 	 * specification. See soup_form_request_new_from_multipart() for more
151 	 * details.
152 	 *
153 	 * Params:
154 	 *     controlName = the name of the control associated with this file
155 	 *     filename = the name of the file, or %NULL if not known
156 	 *     contentType = the MIME type of the file, or %NULL if not known
157 	 *     body_ = the file data
158 	 *
159 	 * Since: 2.26
160 	 */
161 	public void appendFormFile(string controlName, string filename, string contentType, Buffer body_)
162 	{
163 		soup_multipart_append_form_file(soupMultipart, Str.toStringz(controlName), Str.toStringz(filename), Str.toStringz(contentType), (body_ is null) ? null : body_.getBufferStruct());
164 	}
165 
166 	/**
167 	 * Adds a new MIME part containing @data to @multipart, using
168 	 * "Content-Disposition: form-data", as per the HTML forms
169 	 * specification. See soup_form_request_new_from_multipart() for more
170 	 * details.
171 	 *
172 	 * Params:
173 	 *     controlName = the name of the control associated with @data
174 	 *     data = the body data
175 	 *
176 	 * Since: 2.26
177 	 */
178 	public void appendFormString(string controlName, string data)
179 	{
180 		soup_multipart_append_form_string(soupMultipart, Str.toStringz(controlName), Str.toStringz(data));
181 	}
182 
183 	/**
184 	 * Adds a new MIME part to @multipart with the given headers and body.
185 	 * (The multipart will make its own copies of @headers and @body, so
186 	 * you should free your copies if you are not using them for anything
187 	 * else.)
188 	 *
189 	 * Params:
190 	 *     headers = the MIME part headers
191 	 *     body_ = the MIME part body
192 	 *
193 	 * Since: 2.26
194 	 */
195 	public void appendPart(MessageHeaders headers, Buffer body_)
196 	{
197 		soup_multipart_append_part(soupMultipart, (headers is null) ? null : headers.getMessageHeadersStruct(), (body_ is null) ? null : body_.getBufferStruct());
198 	}
199 
200 	/**
201 	 * Frees @multipart
202 	 *
203 	 * Since: 2.26
204 	 */
205 	public void free()
206 	{
207 		soup_multipart_free(soupMultipart);
208 		ownedRef = false;
209 	}
210 
211 	/**
212 	 * Gets the number of body parts in @multipart
213 	 *
214 	 * Returns: the number of body parts in @multipart
215 	 *
216 	 * Since: 2.26
217 	 */
218 	public int getLength()
219 	{
220 		return soup_multipart_get_length(soupMultipart);
221 	}
222 
223 	/**
224 	 * Gets the indicated body part from @multipart.
225 	 *
226 	 * Params:
227 	 *     part = the part number to get (counting from 0)
228 	 *     headers = return location for the MIME part
229 	 *         headers
230 	 *     body_ = return location for the MIME part
231 	 *         body
232 	 *
233 	 * Returns: %TRUE on success, %FALSE if @part is out of range (in
234 	 *     which case @headers and @body won't be set)
235 	 *
236 	 * Since: 2.26
237 	 */
238 	public bool getPart(int part, out MessageHeaders headers, out Buffer body_)
239 	{
240 		SoupMessageHeaders* outheaders = null;
241 		SoupBuffer* outbody_ = null;
242 
243 		auto __p = soup_multipart_get_part(soupMultipart, part, &outheaders, &outbody_) != 0;
244 
245 		headers = ObjectG.getDObject!(MessageHeaders)(outheaders);
246 		body_ = ObjectG.getDObject!(Buffer)(outbody_);
247 
248 		return __p;
249 	}
250 
251 	/**
252 	 * Serializes @multipart to @dest_headers and @dest_body.
253 	 *
254 	 * Params:
255 	 *     destHeaders = the headers of the HTTP message to serialize @multipart to
256 	 *     destBody = the body of the HTTP message to serialize @multipart to
257 	 *
258 	 * Since: 2.26
259 	 */
260 	public void toMessage(MessageHeaders destHeaders, MessageBody destBody)
261 	{
262 		soup_multipart_to_message(soupMultipart, (destHeaders is null) ? null : destHeaders.getMessageHeadersStruct(), (destBody is null) ? null : destBody.getMessageBodyStruct());
263 	}
264 }